import React, { useState } from "react";
import axios from "axios";

const View = ({ postId }) => {
    const [content, setContent] = useState('');
    const onSubmit = (event) => {
        event.preventDefault();
        axios.post(`http://posts.com/posts/${postId}/comments`, {
            content
        });
        setContent('');
    }
    return <div>
        <form onSubmit={onSubmit}>
            <div className="form-group">
                <label>New Comment</label>
                <input className="form-control" value={content} onChange={e => setContent(e.target.value)} />
            </div>
            <button className="btn btn-primary">Submit</button>
        </form>
    </div>
}

export default View;